﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace MyWpfFramework.ViewModels
{
    public partial class GridViewPageViewModel : ObservableRecipient,IRecipient<ValueChangedMessage<DemoDataModel>>
    {
        [ObservableProperty]
        [NotifyPropertyChangedRecipients]
        private ObservableCollection<DemoDataModel> dataList;
        public PersonViewModel PersonViewModel { get; set; }
        public GridViewPageViewModel()
        {
            IsActive = true;
            PersonViewModel =new PersonViewModel();
            DataList = new ObservableCollection<DemoDataModel>();
            DemoDataModel demoDataModel = new DemoDataModel() { Index = 1,Name="张三",IsSelected=true, Remark="这是备注",ImgPath= "/Resources/IconA.png" };
            DemoDataModel demoDataModel2 = new DemoDataModel() { Index = 2,Name="李四",IsSelected=false, Remark="这是备注2",ImgPath= "/Resources/overview.png" };
            DataList.Add(demoDataModel);
            DataList.Add(demoDataModel2);
            
            //Task.Run(async () =>
            //{
            //    while (true)
            //    {
            //        await Task.Delay(2000);
            //        Application.Current.Dispatcher.Invoke(() =>
            //        {
            //        // 在这里更新UI元素
            //        DataList.Add(demoDataModel2);
            //        });
            //    };
              
            //});
                
        }

        [RelayCommand]
        private void AddGrid()
        {
            DemoDataModel demoDataModel2 = new DemoDataModel() { Index = 3, Name = "fasfa", IsSelected = false, Remark = "这是备注1", ImgPath = "/Resources/overview.png" };
            DataList.Add(demoDataModel2);
        }

        public void Receive(ValueChangedMessage<DemoDataModel> message)
        {
            DataList.Add(message.Value);
        }
    }
    public enum DemoType
    {
        Type1 = 1,
        Type2,
        Type3,
        Type4,
        Type5,
        Type6
    }
    public class DemoDataModel
    {
        public int Index { get; set; }

        public string Name { get; set; } = string.Empty;

        public bool IsSelected { get; set; }

        public string Remark { get; set; } = string.Empty;

        public DemoType Type { get; set; }

        public string ImgPath { get; set; } = string.Empty;

       
    }

}
